package com.hang.gymmanager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hang.gymmanager.common.Response;
import com.hang.gymmanager.entity.UserInfoEntity;
import com.hang.gymmanager.req.GetUserInfoPageReq;
import com.hang.gymmanager.req.changeUserStatusReq;
import com.hang.gymmanager.res.UserInfoDetailRes;
import com.hang.gymmanager.res.UserInfoPageRes;
import com.hang.gymmanager.service.UserInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理控制器
 * @author wyq
 * @version v1.0.0
 * @explain
 * @date 2024/3/15 16:44
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/userInfo")
@CrossOrigin
public class UserInfoController {

    private final UserInfoService userInfoService;

    /**
     * 获取用户分页列表
     * @param req
     * @return
     */
    @PostMapping("/all")
    public Response<Page<UserInfoPageRes>> getAllUser(@RequestBody GetUserInfoPageReq req){
        Page<UserInfoPageRes> res = userInfoService.getAllUser(req);
        return Response.success(res);
    }

    /**
     * 用户详细信息
     * @param userId
     * @return
     */
    @GetMapping("/detail/{userId}")
    public Response<UserInfoDetailRes> getUserDetail(@PathVariable Integer userId){
        UserInfoDetailRes res = userInfoService.getUserDetail(userId);
        return Response.success(res);
    }


    /**
     * 切换用户状态
     * @param req
     * @return
     */
    @PostMapping("/changeUserStatus")
    public Response changeUserStatus(@RequestBody changeUserStatusReq req){
        userInfoService.changeUserStatus(req);
        return Response.success();
    }

    /**
     * 重置用户密码
     * @param userId
     * @return
     */
    @GetMapping("/resetPassword/{userId}")
    public Response resetPassword(@PathVariable Integer userId){
        userInfoService.resetPassword(userId);
        return Response.success();
    }


}
